home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1995 November / Macworld Nov ’95.toast / Developers / Selection ƒ 2.5 / teRec < prev    next >
Encoding:
Text File  |  1994-11-06  |  1.7 KB  |  99 lines  |  [TEXT/MSET]

  1. \ 28Oct94 dbh updated to 2.5 syntax 
  2.  
  3. (*
  4.  
  5. Class terec is strictly intended for use as a way to conveniently access the
  6. Mac toolbox data structure for a TextEdit record.  As can be seen in class te,
  7. as is shown in the example, we don't instantiate a terec object or ivar.
  8. Instead, we obtain a pointer to the record ( ptr: TEHandle, in this case)
  9. and then pass a message to the class itself!
  10.  
  11. *)
  12.  
  13.  
  14. :class teRec super{ object }
  15.     record{
  16.     rect+    destRect
  17.     rect+    viewRect
  18.     rect+    selRect
  19.     int        lineHeight
  20.     int        fontAscent
  21.     point    selPoint
  22.     int        selStart
  23.     int        selEnd
  24.     int        active
  25.     ptr        wordBreak
  26.     ptr        clikLoop
  27.     12 bytes 1terec \ unmapped
  28.     int      just
  29.     int      teLength
  30.     handle  htext
  31.     6 bytes 2terec \ unmapped
  32.     int  crOnly
  33.     int  txFont
  34.     int  txFace
  35.     int  txMode
  36.     int  txSize
  37.     ptr  inPort        \ the wptr
  38.     8 bytes 3terec    \ unmapped
  39.     int  nlines
  40.     0 bytes lineStarts
  41.     }
  42.  
  43. :m setlineHeight:    ( n -- )
  44.     put: lineHeight ;m
  45.  
  46. :m lineHeight:    ( -- n )
  47.     get: lineHeight ;m
  48.  
  49. :m #lines:    ( -- n )
  50.     get: nlines ;m
  51.  
  52. :m selStart: ( -- n )
  53.     get: selStart ;m
  54.  
  55. :m selEnd: ( -- n )
  56.     get: selEnd ;m
  57.  
  58. :m getselect: ( -- addr len )    \ returns hilited selection
  59.     ptr: htext selstart: self +  ( addr)
  60.     selend: self selstart: self -  ( len) ;m
  61.  
  62. :m addrLineStart:   ( -- addr)
  63.     lineStarts ;m
  64.  
  65. :m size: ( -- n )
  66.     get: teLength ;m
  67.  
  68. :m moveto:    { l t -- }
  69.     l t moveto: destRect 
  70.     l t moveto: viewRect ;m
  71.  
  72. :m setview:    ( l t r b -- )
  73.     put: viewRect ;m
  74.  
  75. :m setdest:    ( l t r b -- )
  76.     put: destRect ;m
  77.  
  78. :m move: { dx dy -- }
  79.     dx dy move: destRect
  80.     dx dy move: viewRect ;m
  81.  
  82. :m gettextaddr:  ( -- addr )
  83.     get: htext @ ;m
  84.  
  85. :m noWrap:
  86.     -1 put: crOnly ;m
  87.     
  88. ;class
  89.  
  90. endload
  91.  
  92. *** EXAMPLE USE
  93.  
  94. (from class te)
  95.  
  96. :m setlineHeight:    ( n -- )
  97.     ptr: TEHandle setlineHeight: teRec ;m
  98.  
  99.